<template>
  <div class="z-wallet" :class="{'z-wallet-h5': piniaSystem.getIsH5}">
    <div class="z-wallet__header">
      <div class="z-wallet__header-selector" ref="zwalletRef">
        <div class="z-wallet__header-selector__title" @click="openWalletSelector">
          <img :src="currentWallet.currencyIcon" class="wallet-icon">
          <span class="wallet-money">{{  currentWallet.currencyName  }}</span>
          <i-iconoir-nav-arrow-down :class="{'opened': visiblePcWallet}"/>
        </div>
        <div class="z-wallet__header-selector__box" v-if="visiblePcWallet">
          <div class="z-wallet__header-selector__box-middle">
            <div
              class="z-wallet__header-selector__item"
              v-for="wallet in wallets" :key="wallet.currencyId"
              :class="{'active': wallet.currencyId === currentWallet.currencyId}"
              @click="choiceWallet(wallet)"
            >
              <img :src="wallet.currencyIcon" class="wallet-icon">
              <span>{{ wallet.currencyName }}</span>
              <i-ph-check-bold />
            </div>
          </div>
        </div>
      </div>
      <div class="z-wallet__header-money">
        <span class="wallet-money">{{  Number(currentWallet.money).toFixed(2) }}</span>
      </div>
    </div>
    <div class="z-wallet__btn-tabs">
      <span
        v-for="btn in btnColumns"
        :key="btn.id"
        :class="{'active': btnActive === btn.id}"
        @click="changeBtnTabs(btn)"
      >
        {{ btn.name }}
      </span>
    </div>
    <!-- 充值 -->
    <div class="z-wallet__main" v-if="btnActive === 1">
      <ZTab
        v-model:navs="handlerBank"
        v-model:active="navsActive"
        layout="left"
        @change="changeTabs"
      />
      <!-- BRL -->
      <el-form @submit.native.prevent :model="form" label-position="top" v-if="piniaUserinfo.getCurrentWallet.currencyType == 0" ref="formRef" :rules="rules">
        <el-form-item :label="t('WALLET.BANKCODE')" prop="bankCode" v-if="currentBuyType.code == 18">
          <el-select v-model="form.bankCode" filterable size="large" :placeholder="t('WALLET.BANKCODE')">
            <el-option
              v-for="item in bankList"
              :key="item.bankCode"
              :label="item.bankName"
              :value="item.bankCode"
            />
          </el-select>
        </el-form-item>
        <el-form-item :label="t('WALLET.RechargeAmount')" prop="rechargeMoney">
          <el-input v-model="form.rechargeMoney" @blur="checkRechargeMoney" type="number"/>
        </el-form-item>
        <el-form-item>
          <ul class="quick-money-list">
            <li v-for="item in moneyList" :key="item" @click="fillMoney(item)">{{ item }}</li>
          </ul>
        </el-form-item>
        <div class="wallet-gift-tips">
          {{t('WALLET.MinAmount')}} {{ currentBuyType.currencyParam.minMoney }}
        </div>
        <!-- 优惠 -->
        <Preferential v-model:money="form.rechargeMoney" v-model:accept="accept" v-model:limit="limit" v-model:hasOffer="hasOffer"/>
        <el-form-item>
          <el-button type="primary" :loading="loading.recharge" @click="recharge">{{ t("WALLET.Buy") }}</el-button>
        </el-form-item>
      </el-form>
      <!-- 虚拟货币 二维码等等 -->
      <el-form :model="form" label-position="top" v-if="piniaUserinfo.getCurrentWallet.currencyType == 1" :rules="rules">
        <el-form-item>
          <div class="wallet-pay-qrcode">
            <p class="no-data" v-if="!rechargeUrl">
              {{ t('BetRecord.Nocontent') }}
            </p>
            <QrcodeVue v-else :value="rechargeUrl" :size="200" level="H" id="picture"/>
            <p class="save-link" @click="downloadImage('picture')">
              {{ t("WALLET.SaveQR") }}
            </p>
            <p class="charge-address">
              {{ t("WALLET.RechargeAdds") }}
            </p>
            <p class="charge-address-cotnent" :class="{'charge-address-cotnent-h5': piniaSystem.getIsH5}">
              <span>{{rechargeUrl}}</span>
              <IIonCopyOutline @click="copy(rechargeUrl)"/>
            </p>
            <!-- 优惠 -->
            <Preferential v-model:money="form.rechargeMoney" v-model:accept="accept" v-model:limit="limit" v-model:hasOffer="hasOffer"/>
            <p class="charge-tips">
              <span>{{ t("WALLET.Recovered").replace("#", currentBuyType.name) }}</span>
              <span>{{ t("WALLET.Confirmation") }}</span>
            </p>
          </div>
        </el-form-item>
      </el-form>
    </div>
    <!-- 提现 -->
    <div class="z-wallet__main" v-if="btnActive === 2">
      <ZTab
        v-model:navs="handlerBank"
        v-model:active="navsActive"
        layout="left"
        @change="changeTabs"
        v-if="piniaUserinfo.getCurrentWallet.currencyId == '1005'"
      />
      <!-- 非虚拟 -->
      <el-form :model="withdrawalForm" ref="withdrawalFormRef" label-position="top" v-if="piniaUserinfo.getCurrentWallet.currencyType == 0" :rules="withdrawalRules">
        <!-- BRL提现 -->
        <div class="pixBuy" v-if="piniaUserinfo.getCurrentWallet.currencyId == '1001'">
          <span>{{ t('userData.platform01') }}：</span> <span class="secondPay">{{ t('userData.platform02')
          }}</span>
        </div>
        <!-- BRL提现 账户类型 默认-->
        <el-form-item :label="t('WALLET.accoutType')" prop="bankCode" v-if="piniaUserinfo.getCurrentWallet.currencyId == '1001'">
          <el-select v-model="withdrawalForm.bankCode" filterable size="large" :placeholder="t('WALLET.accoutType')">
            <el-option
              v-for="item in bankList"
              :key="item.bankCode"
              :label="item.bankCode"
              :value="item.bankCode"
            />
          </el-select>
        </el-form-item>
        <!-- BRL提现 账户 默认-->
        <el-form-item class="z-form-item-flex" :label="t('WALLET.account')" prop="bankNumber" v-if="piniaUserinfo.getCurrentWallet.currencyId == '1001'">
          <el-select v-model="withdrawalForm.lauselected" :placeholder="t('WALLET.account')" class="phone-selector" filterable size="large" v-if="withdrawalForm.bankName === 'PHONE'">
            <el-option
              v-for="item in phoneList"
              :key="item.countryCode"
              :label="item.countryCode"
              :value="item.countryCode"
            >
              <span class="withdrawal-phone-options">
                <img :src="item.resource" alt=""> {{ item.countryCode }}
              </span>
            </el-option>
          </el-select>
          <el-input v-model="withdrawalForm.bankNumber" />
        </el-form-item>
        <!-- BRL提现 账户类型 手机 和 邮箱 -->
        <el-form-item :label="t('WALLET.accoutType')" prop="bankName" v-if="piniaUserinfo.getCurrentWallet.currencyId == '1001' && (
          withdrawalForm.bankCode === 'PHONE' || withdrawalForm.bankCode === 'EMAIL'
        )">
          <el-select v-model="withdrawalForm.bankName" filterable size="large" :placeholder="t('WALLET.accoutType')">
            <el-option
              v-for="item in bankList.filter((item:any) => item.bankCode == 'CNPJ' || item.bankCode == 'CPF')"
              :key="item.bankCode"
              :label="item.bankName"
              :value="item.bankCode"
            />
          </el-select>
        </el-form-item>
        <!-- BRL提现 账户 手机 和 邮箱-->
        <el-form-item :label="t('WALLET.account')" prop="cpf" v-if="piniaUserinfo.getCurrentWallet.currencyId == '1001' && (
          withdrawalForm.bankCode === 'PHONE' || withdrawalForm.bankCode === 'EMAIL'
        )">
          <el-input v-model="withdrawalForm.cpf" type="number"/>
        </el-form-item>
        <!-- BRL提现 提款金额 -->
        <el-form-item :label="t('WALLET.Amount')" prop="money" v-if="piniaUserinfo.getCurrentWallet.currencyId == '1001'">
          <el-input v-model="withdrawalForm.money" type="number"></el-input>
        </el-form-item>


        <!-- VND和INR提现 开户名称 -->
        <el-form-item :label="t('WALLET.BANKUSER')" prop="bankAccountName" v-if="piniaUserinfo.getCurrentWallet.currencyId !== '1001'">
          <el-input v-model="withdrawalForm.bankAccountName"></el-input>
        </el-form-item>
        <!-- VND和INR提现 开户电话 -->
        <el-form-item :label="t('WALLET.openAccount')" prop="phone" v-if="piniaUserinfo.getCurrentWallet.currencyId !== '1001'">
          <el-input v-model="withdrawalForm.phone"></el-input>
        </el-form-item>
        <!-- VND和INR提现 开户邮件 -->
        <el-form-item :label="t('WALLET.Email')" prop="email" v-if="piniaUserinfo.getCurrentWallet.currencyId !== '1001'">
          <el-input v-model="withdrawalForm.email"></el-input>
        </el-form-item>
        <!-- VND和INR提现 开户银行 -->
        <el-form-item :label="t('WALLET.BANKCODE')" prop="bankName" v-if="piniaUserinfo.getCurrentWallet.currencyId !== '1001'">
          <el-select v-model="withdrawalForm.bankName" filterable size="large" :placeholder="t('WALLET.BANKCODE')">
            <el-option
              v-for="item in bankList"
              :key="item.bankCode"
              :label="item.bankName"
              :value="item.bankCode"
            />
          </el-select>
        </el-form-item>
        <!-- VND和INR提现 银行账户 -->
        <el-form-item :label="t('WALLET.BANKACCOUNT')" prop="bankNumber" v-if="piniaUserinfo.getCurrentWallet.currencyId !== '1001'">
          <el-input v-model="withdrawalForm.bankNumber"></el-input>
        </el-form-item>
        <!-- VND和INR提现 提款金额 -->
        <el-form-item :label="t('WALLET.Amount')" prop="money" v-if="piniaUserinfo.getCurrentWallet.currencyId !== '1001'">
          <el-input v-model="withdrawalForm.money"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" :loading="loading.withdrawal" @click="withdrawal('notVirtually')">{{ t("WALLET.WITHDRAW") }}</el-button>
        </el-form-item>
      </el-form>
      <!-- 虚拟 -->
      <el-form :model="withdrawalForm" ref="usdtFormRef" label-position="top" v-if="piniaUserinfo.getCurrentWallet.currencyType == 1" :rules="usdtRules">
        <!-- 提现地址 -->
        <el-form-item :label="t('userData.inputWalletAddress').replace('#', currentBuyType.code == 5 ? '42' : '34')" prop="address">
          <el-input v-model="withdrawalForm.address" :placeholder="t('userData.inputWalletAddress').replace('#', currentBuyType.code == 5 ? '42' : '34')"></el-input>
        </el-form-item>
        <!-- 提款金额 -->
        <el-form-item :label="t('WALLET.WithdrawMoney')" prop="money">
          <el-input v-model="withdrawalForm.money" type="number"></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" :loading="loading.withdrawal" @click="withdrawal('virtually')">{{ t("WALLET.WITHDRAW") }}</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>
  <component
    :is="whichPopupType"
    position="bottom"
    closeable
    v-model:show="dialogConfig.show"
    v-model:visible="dialogConfig.show"
    v-model:title="dialogConfig.title"
    :width="dialogConfig.width"
    :headerFixed="dialogConfig.headerFixed"
    :auto-height="true"
  >
    <!-- 取款密码 -->
    <el-form :model="withdrawalForm" class="inputCardPwd" label-position="top" ref="withdrawalPasswordRef" :rules="withdrawalPasswordRules">
      <el-form-item :label="t('WALLET.inputCardPwd')" prop="password">
        <el-input v-model="withdrawalForm.password" type="password" :placeholder="t('WALLET.inputCardPwd')"></el-input>
      </el-form-item>
      <div class="withdrawal-forget-password" @click="openForgetpassword"><span>{{t("WALLET.forgetPwd")}}</span></div>
      <el-form-item>
        <el-button type="primary" :loading="loading.withdrawal" @click="withdrawalSure">{{ t("WALLET.sure") }}</el-button>
      </el-form-item>
    </el-form>
  </component>
  <component
    :is="whichPopupType"
    position="bottom"
    closeable
    v-model:show="dialogResetPassword.show"
    v-model:visible="dialogResetPassword.show"
    v-model:title="dialogResetPassword.title"
    :width="dialogResetPassword.width"
    :headerFixed="dialogResetPassword.headerFixed"
    :auto-height="true"
  >
    <!-- 忘记密码 -->
    <Forgetpassword @back="dialogResetPassword.show = false" v-model:isPhoneLogin="isPhoneLogin" class="wallet-forget-password"/>
  </component>
</template>

<script setup lang="ts" name="Wallet">
import walletApi from '@/api/modules/wallet';
import userinfo from '@/store/userinfo';
import system from '@/store/system';
import { useClickAway } from '@vant/use';
import { copy, downloadImage } from '@/utils/format';

const piniaUserinfo:any = userinfo();
const piniaSystem:any = system();
const emits = defineEmits(['openEmailContent'])
const { t } = useI18n();

const whichPopupType = computed(()=>{
  return piniaSystem.getIsH5 ?
    markRaw(defineAsyncComponent(() => import('vant/es/popup'))) :
    markRaw(defineAsyncComponent(() => import('@/components/Dialog/index.vue')));
});

// 当前钱包
const currentWallet = computed(()=> piniaUserinfo.getCurrentWallet);
// 钱包夹
const wallets = computed(()=>piniaUserinfo.getWallet);

const data:any = reactive({
  visiblePcWallet: false,
  moneyList: ['20','50','100','500','1,000','5,000','10,000','20,000'],
  btnColumns: [
    {
      name: t("WALLET.Buy"),
      id: 1
    },
    {
      name: t("WALLET.Withdraw"),
      id: 2
    },
  ],
  dialogConfig: {
    show: false,
    type: '',
    headerFixed: true,
    width: 400,
    autoHeight: true
  },
  dialogResetPassword: {
    show: false,
    type: '',
    headerFixed: true,
    width: 400,
    autoHeight: true
  },
  btnActive: 1,
  navsActive: '',
  currentBuyType: {
    currencyParam: {}
  }, // 当前重置类型
  form: {},
  rules: {
    bankCode: [
      { required: true, message: `${t('WALLET.BankCodeRule')}`, trigger: 'blur' },
    ],
    rechargeMoney: [
      { required: true, message: `${t('WALLET.BuyMoneyRule')}`, trigger: 'blur' },
    ],
  },
  withdrawalRules: {
    bankAccountName: [
      { required: true, message: `${t('WALLET.BankRule')}`, trigger: 'blur' },
    ],
    phone: [
      { required: true, message: `${t('WALLET.PhoneRule')}`, trigger: 'blur' },
    ],
    email: [
      { required: true, message: `${t('WALLET.EmailRule')}`, trigger: 'blur' },
    ],
    bankName: [
      { required: true, message: `${t('WALLET.accountRule')}`, trigger: 'change' },
    ],
    bankCode: [
      { required: true, message: `${t('WALLET.BankCodeRule')}`, trigger: 'change' },
    ],
    lauselected: [
      { required: true, message: `${t('WALLET.areaRule')}`, trigger: 'blur' },
    ],
    money: [
      { required: true, message: `${t('WALLET.WithdrawMoneyRule')}`, trigger: 'blur' },
    ],
    bankNumber: [
      { required: true, message: `${t('WALLET.AccountRule')}`, trigger: 'blur' },
      { validator: (rule: any, value: any, callback: any) => {
        if (value === '') {
          callback(new Error(t('WALLET.AccountRule')))
        } else if (withdrawalForm.value.bankCode === 'CPF' && !/^\d{11}$/.test(value)) {
          callback(t('userData.CPFRule'))
        }  else if (withdrawalForm.value.bankCode === 'CNPJ' && !/^\d{14}$/.test(value)) {
          callback(t('userData.CNPJRule'))
        }  else if (withdrawalForm.value.bankCode === 'EMAIL' && !/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(value)) {
          callback(t('Message.code_1001'))
        }  else if (withdrawalForm.value.bankCode === 'PHONE' && !/^\d{11}$/.test(value)) {
          callback(t('userData.CPFRule'))
        } else {
          callback()
        }
      }, trigger: 'blur' },
    ],
    cpf: [
      { required: true, message: `${t('WALLET.AccountRule')}`, trigger: 'blur' },
      { validator: (rule: any, value: any, callback: any) => {
        if (value === '') {
          callback(new Error(t('WALLET.AccountRule')))
        } else if (withdrawalForm.value.bankName === 'CPF' && !/^\d{11}$/.test(value)) {
          callback(t('userData.CPFRule'))
        }  else if (withdrawalForm.value.bankName === 'CNPJ' && !/^\d{14}$/.test(value)) {
          callback(t('userData.CNPJRule'))
        }  else if (withdrawalForm.value.bankName === 'EMAIL' && !/^[a-zA-Z0-9_-]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/.test(value)) {
          callback(t('Message.code_1001'))
        }  else if (withdrawalForm.value.bankName === 'PHONE' && !/^\d{11}$/.test(value)) {
          callback(t('userData.CPFRule'))
        } else {
          callback()
        }
      }, trigger: 'blur' },
    ],
  },
  isPhoneLogin: false,
  usdtRules: {
    address: [
      { required: true, message: `${t('WALLET.AddressRule')}`, trigger: 'blur' },
      { validator: (rule: any, value: any, callback: any) => {
        const len = currentBuyType.value.code == 5 ? 42 : 34;
        if (value === '') {
          callback(new Error(t('WALLET.AddressRule')))
        } else if (len === 42 && !/^[\d\w]{42}$/.test(value)) {
          callback(t('WALLET.widthdrawAddressRule'))
        } else if (len === 34 && !/^[\d\w]{34}$/.test(value)) {
          callback(t('WALLET.widthdrawAddressRules'))
        } else {
          callback()
        }
      }, trigger: 'blur' },
    ],
  },
  usdtFormRef: null,
  withdrawalFormRef: null,
  zwalletRef: null,
  loading: {
    recharge: false,
    withdrawal: false
  },
  rechargeUrl: "",
  bankList: [],
  withdrawalForm: {},
  phoneList: computed(()=> piniaSystem.getLangList),
  limit: null,
  ifLevel: 0,
  accept: null,
  hasOffer: {},
  formRef: null,
  withdrawalPasswordRef: null,
  withdrawalPasswordRules: {
    password: [
      { required: true, message: `${t('WALLET.inputCardPwd')}`, trigger: 'blur' },
    ],
  },
});

const {
  visiblePcWallet,
  btnColumns,
  moneyList,
  dialogConfig,
  dialogResetPassword,
  btnActive,
  navsActive,
  currentBuyType,
  form,
  rules,
  zwalletRef,
  loading,
  rechargeUrl,
  bankList,
  withdrawalForm,
  phoneList,
  limit,
  ifLevel,
  accept,
  hasOffer,
  formRef,
  withdrawalRules,
  usdtFormRef,
  withdrawalFormRef,
  usdtRules,
  withdrawalPasswordRef,
  withdrawalPasswordRules,
  isPhoneLogin,
} = toRefs(data);

piniaUserinfo.setDigitalWallet();

// 打开选择器
const openWalletSelector = () => {
  visiblePcWallet.value = !visiblePcWallet.value;
}

// 选择钱显示
const choiceWallet = (wallet:any) => {
  visiblePcWallet.value = false;
  piniaUserinfo.setCurrentWallet(wallet);
  getBankCodeList();
  getLevelPayStatus();
}

// 填充金钱
const fillMoney = (item: string) => {
  form.value.rechargeMoney = item.replaceAll(',', '');
}

// 切换按钮
const changeBtnTabs = (btn: any) => {
  btnActive.value = btn.id;
}

watch(
  () => currentBuyType.value,
  (val, preVal) => {
    if(val && val.currencyParam && val.currencyParam.currencyId === '1005'){
      depositQRcode();
    }
    if(val){
      // 填充最低金额
      form.value.rechargeMoney = currentBuyType.value.currencyParam.minMoney;
      getBankCodeList();
      getLevelPayStatus();
    }
  },
  { immediate: false, deep: true },
);

watch(
  () => piniaUserinfo.currentWallet,
  (val, preVal) => {
    piniaUserinfo.setDigitalWallet();
  },
  { immediate: false, deep: true },
);

// 提款
const withdrawal = (type: string) => {
  let whichRef = withdrawalFormRef.value;
  if(type === 'notVirtually'){
    whichRef = withdrawalFormRef.value;
  }else if(type === 'virtually'){
    whichRef = usdtFormRef.value;
  }
  whichRef.validate((valid:any) => {
    if (valid) {
      dialogConfig.value.show = true;
      dialogConfig.value.withdrawalType = type;
    }
  })
}

const withdrawalSure = () => {
  withdrawalPasswordRef.value.validate((valid:any) => {
    if (valid) {
      // 要先验证密码
      walletApi.findUserWithdrawPs({
        password: withdrawalForm.value.password
      }).then((response:any)=>{
        if(response.code === 200){
          dialogConfig.value.show = false;
          nextTick(()=>{
            if(dialogConfig.value.withdrawalType === 'virtually'){
              // 虚拟提现
              walletApi.userTransfer({
                ...withdrawalForm.value,
                channelCode: currentBuyType.value.code, //默认就是写死的
                currencyId: piniaUserinfo.getCurrentWallet.currencyId, // 当前货币id
              });
            }else{
              // 非虚拟提现
              walletApi.cashAuth({
                ...withdrawalForm.value,
                channelCode: 26, //默认就是写死的
                ifWithhold: 1,
                email: piniaUserinfo.getUserinfo.user.email,
                isLevel: 1,
                currencyId: piniaUserinfo.getCurrentWallet.currencyId, // 当前货币id
              });
            }
          })
        }
      });
    }
  })
}

// 切换类型
const changeTabs = ({nav, index}:any) => {
  currentBuyType.value = nav;
}

const depositQRcode = () => {
  if(btnActive.value === 1){
    loading.value.recharge = true;
    walletApi.depositQRcode({
      code: currentBuyType.value.code
    }).then((response:any)=>{
      console.log("充值地址", response)
      if(response.code === 200){
        rechargeUrl.value = response.data || "";
      }
    }).finally(()=>{
      loading.value.recharge = false;
    });
  }
}

// 充值
const recharge = () => {
  formRef.value.validate((valid:any) => {
    if (valid) {
      loading.value.recharge = true;
      walletApi.threePay({
        channelCode: currentBuyType.value.code,
        currencyId: piniaUserinfo.getCurrentWallet.currencyId,
        money: form.value.rechargeMoney,
        bankCode: form.value.bankCode,
        returnUrl: window.location.href,
        ifJoin: accept.value,
        ifLevel: accept.value,
      }).then((response:any)=>{
        console.log(response)
        if(response.code === 200){
          if (['28', '44', '48', '50', '52'].indexOf(currentBuyType.value.code) >= 0){
            window.location.href = response.data
          }else{
            window.open(response.data, "_blank")
          }
        }
      }).finally(()=>{
        loading.value.recharge = false;
      });
    } else {
    }
  })
}

// 开户银行
const getBankCodeList = () => {
  walletApi.getBankCodeList({
    channelCode: currentBuyType.value.code,
    currencyId: piniaUserinfo.getCurrentWallet.currencyId,
  }).then((response:any)=>{
    if(response.code === 200){
      bankList.value = response.rows || [];
    }
  }).finally(()=>{
    loading.value.recharge = false;
  });
}

// 个人层级
const getLevelPayStatus = () => {
  walletApi.getLevelPayStatus({
    channelCode: currentBuyType.value.code,
    currencyId: piniaUserinfo.getCurrentWallet.currencyId,
  }).then((response: any)=>{
    if(response.code === 200){
      if(response.data){
        hasOffer.value = response.data;
        limit.value = response.data.limit;
        console.log("limit", limit.value)
        if (response.data.discountGiveUp) {
          accept.value = '1'
        }
      }else{
        ifLevel.value = 0;
      }
    }else{
      ifLevel.value = 0;
    }
  });
}

// 打开忘记密码
const openForgetpassword = () => {
  dialogResetPassword.value.show = true;
  dialogResetPassword.value.show = piniaSystem.getIsH5 ? "100%" : 400;
}

// 钱包类型
const handlerBank = computed(() => {
  const result:any = [];
  piniaUserinfo.getDigitalWallet.map((im:any, index:number)=>{
    if((btnActive.value == 1 && im.platformType == 2) || (btnActive.value == 2 && im.platformType == 1)){
      result.push({
        ...im,
        currencyParam: JSON.parse(im.currencyParam)[0],
        active: im.id,
        label: im.name
      });
    }
  });
  if(result.length > 0){
    currentBuyType.value = result[0];
    navsActive.value = result[0].id;
  }
  return result;
});

const checkRechargeMoney = () => {
  console.log(currentBuyType.value)
  if(
    currentBuyType.value &&
    currentBuyType.value.currencyParam &&
    currentBuyType.value.currencyParam.minMoney &&
    currentBuyType.value.currencyParam.maxMoney
  ){
    if(Number(form.value.rechargeMoney) > currentBuyType.value.currencyParam.maxMoney){
      form.value.rechargeMoney = currentBuyType.value.currencyParam.maxMoney;
    }else if(Number(form.value.rechargeMoney) < currentBuyType.value.currencyParam.minMoney){
      form.value.rechargeMoney = currentBuyType.value.currencyParam.minMoney;
    }
  }
}

useClickAway(zwalletRef, () => {
  visiblePcWallet.value = false;
});

defineExpose({
});
</script>

<style lang="scss" scoped>
@import url('./index.scss');
.wallet-forget-password{
  padding: var(--rem-20);
}
</style>
